package hot100.h0912;

import java.util.ArrayList;
import java.util.List;

/**
  * @description 二叉树的中序遍历
  * @author 不知名帅哥
  * @date 2024/9/12 20:32
  * @version 1.0
*/
public class BinaryTreeInorder {
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        getRes(root,res);
        return res;
    }

    private void getRes(TreeNode root, List<Integer> res) {
        if (root==null){
            return;
        }
        getRes(root.left,res);
        res.add(root.val);
        getRes(root.right,res);
    }

    public static void main(String[] args) {
        BinaryTreeInorder binaryTreeInorder = new BinaryTreeInorder();
        TreeNode root=new TreeNode(1);
        root.left=new TreeNode(2);
        root.right=new TreeNode(3);
        System.out.println(binaryTreeInorder.inorderTraversal(root));
    }
}
